package com.phkj.qdh.ui.adapter.teamlawnode

import android.widget.CheckBox
import android.widget.RelativeLayout
import com.phkj.qdh.R
import com.phkj.qdh.ui.dialog.TeamOrLawTreeSelectDialog
import com.phkj.qdh.utils.node.BaseNode
import com.phkj.qdh.utils.node.BaseNodeProvider
import com.phkj.qdh.utils.node.BaseViewHolder

class TeamTreeContentProvider(val dialog: TeamOrLawTreeSelectDialog) : BaseNodeProvider() {
    override val itemViewType: Int
        get() = 2
    override val layoutId: Int
        get() = R.layout.item_employee_select_content

    override fun convert(helper: BaseViewHolder, item: BaseNode) {
        val data = item as TeamSortContentNode
        val cb = helper.getView<CheckBox>(R.id.cb)
        helper.setText(R.id.tv_name, item.content.name)
        cb.setOnCheckedChangeListener(null)
        cb.isChecked = item.isSelected
//        cb.setOnCheckedChangeListener { btn, b ->
//            when (b) {
//                true -> {
//
//                    item.isSelected = true
//                }
//
//                false -> {
//                    item.isSelected = false
//                }
//            }
//
//        }

        helper.getView<RelativeLayout>(R.id.ll).setOnClickListener {
//            getAdapter()?.data?.forEach { head ->
//                head as TeamSortHeadNode
//                head.isSelected = false
//                head.child?.forEach { content ->
//                    content as TeamSortContentNode
//                    content.isSelected = false
//
//                }
//            }


            dialog.nodeList.forEach { head ->
                head as TeamSortHeadNode
                head.isSelected = false
                head.child?.forEach { child ->
                    child as TeamSortContentNode
                    child.isSelected = false
                }
            }

            item.isSelected = true
            cb.isChecked = item.isSelected
            getAdapter()?.notifyDataSetChanged()

        }
    }
}